#!usr/bin/env python
# -*- coding:utf-8 -*-
# user nanme: Mr.zhang
# data time : 2022/9/16   6:31 下午
# project   : init_data.py
# IDE       : PyCharm
# email     :17600960626@163.com
import re

from drivers.android import devices
from lib.read_data import data
from lib.loggers import log
import os
import pytest

BASE_PATH = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))


def get_data(file_name):

    data_file_path = os.path.join(BASE_PATH, "data", file_name)
    if '.yml' in file_name:
        test_data = data.load_yaml(data_file_path)
    if '.json' in file_name:
        test_data = data.load_json(data_file_path)
    if '.ini' in file_name:
        test_data = data.load_ini(data_file_path)

    return test_data


def get_vm_size():
    # 获取分辨率
    cmd = os.popen('adb -s %s shell wm size'%devices()[0])
    vm_size = cmd.read()
    cmd.close()
    vm_size_list = re.findall(r'(\d+)', vm_size)
    return vm_size_list

def get_path(path):  # '/layout/candidate_layout'
    """
    :param path: 文件相对路径
    :return: 文件绝对路径
    """
    script_path_up = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    data_path = script_path_up + path
    return data_path